import chisel3._
import chisel3.util._

class Counter(max_num : Int) extends Module{
  val io = IO(new Bundle(){
    val tick = Output(Bool())
  })

  val width = log2Up(max_num)

  val cntReg = RegInit(0.U(width.W))

  when(cntReg === (max_num - 1).U){
    cntReg := 0.U
    io.tick := true.B
  }.otherwise{
    cntReg := cntReg + 1.U
    io.tick := false.B
  }
}
